/*
 * Copyright 2012-2021 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.boot.autoconfigure.web.reactive;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.http.codec.multipart.DefaultPartHttpMessageReader;
import org.springframework.util.unit.DataSize;

/**
 * 用于配置 Spring Webflux 中 multipart 支持的 {@link ConfigurationProperties 配置属性}。用于配置 {@link DefaultPartHttpMessageReader}。
 *
 * @author Chris Bono
 * @since 2.6.0
 */
@ConfigurationProperties(prefix = "spring.webflux.multipart")
public class ReactiveMultipartProperties {

	/**
	 * 每个部分允许的最大内存大小，超过则写入磁盘。设置为 -1 表示所有内容均存储在内存中。开启流式处理时此属性无效。
	 */
	private DataSize maxInMemorySize = DataSize.ofKilobytes(256);

	/**
	 * 每个部分头部允许的最大内存大小。设置为 -1 表示无限制。
	 */
	private DataSize maxHeadersSize = DataSize.ofKilobytes(10);

	/**
	 * 每个部分允许的最大磁盘使用量。默认值为 -1，表示无限制。开启流式处理时此属性无效。
	 */
	private DataSize maxDiskUsagePerPart = DataSize.ofBytes(-1);

	/**
	 * 单个 multipart 请求允许的最大部分数量。默认值为 -1，表示无限制。
	 */
	private Integer maxParts = -1;

	/**
	 * 是否直接从解析后的输入缓冲流中进行流式处理，而不存储到内存或文件中。默认值为非流式处理。
	 */
	private Boolean streaming = Boolean.FALSE;

	/**
	 * 存储大于 'maxInMemorySize' 的文件部分的目录。默认是在系统临时目录下创建名为 'spring-multipart' 的目录。开启流式处理时此属性无效。
	 */
	private String fileStorageDirectory;

	/**
	 * 用于解码头部的字符集。
	 */
	private Charset headersCharset = StandardCharsets.UTF_8;

	public DataSize getMaxInMemorySize() {
		return this.maxInMemorySize;
	}

	public void setMaxInMemorySize(DataSize maxInMemorySize) {
		this.maxInMemorySize = maxInMemorySize;
	}

	public DataSize getMaxHeadersSize() {
		return this.maxHeadersSize;
	}

	public void setMaxHeadersSize(DataSize maxHeadersSize) {
		this.maxHeadersSize = maxHeadersSize;
	}

	public DataSize getMaxDiskUsagePerPart() {
		return this.maxDiskUsagePerPart;
	}

	public void setMaxDiskUsagePerPart(DataSize maxDiskUsagePerPart) {
		this.maxDiskUsagePerPart = maxDiskUsagePerPart;
	}

	public Integer getMaxParts() {
		return this.maxParts;
	}

	public void setMaxParts(Integer maxParts) {
		this.maxParts = maxParts;
	}

	public Boolean getStreaming() {
		return this.streaming;
	}

	public void setStreaming(Boolean streaming) {
		this.streaming = streaming;
	}

	public String getFileStorageDirectory() {
		return this.fileStorageDirectory;
	}

	public void setFileStorageDirectory(String fileStorageDirectory) {
		this.fileStorageDirectory = fileStorageDirectory;
	}

	public Charset getHeadersCharset() {
		return this.headersCharset;
	}

	public void setHeadersCharset(Charset headersCharset) {
		this.headersCharset = headersCharset;
	}

}
